package net.csdn.business.common.oauth2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.common.oauth2.model.entity.PersonalAccessToken;
import net.csdn.business.common.domain.request.oauth.PersonalAccessTokenQuery;
import net.csdn.business.common.domain.vo.oauth.PersonalAccessTokenVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * personalToken信息表;(person_token)表数据库访问层
 * @author : duweiwei
 * @date : 2022-12-12
 */
@Mapper
public interface PersonalAccessTokenMapper extends BaseMapper<PersonalAccessToken>{


    /**
     * 分页查询私人token
     */
    @Select("<script> select id, object_id,user_id, token_name, scopes, expire_time, " +
            " used_count,last_use_time, revoked, is_delete, created_date,  last_modified_date " +
            " from personal_access_token where is_delete=0 and  revoked=0 " +
            "<if test='query.userId != null  and query.userId != \"\"' >" +
            " AND user_id = #{query.userId} " +
            "</if>" +
            " order by created_date desc" +
            " </script>")
    public List<PersonalAccessTokenVO> findPageList(Page page, @Param("query") PersonalAccessTokenQuery query);



    /**
     * 根据条件查询私人token
     */
    @Select("<script> select id, token_id , object_id, user_id, token_name, scopes, expire_time, " +
            " used_count,last_use_time, revoked, is_delete, created_date,  last_modified_date " +
            " from personal_access_token where is_delete=0 and  revoked=0 " +
            "<if test='query.userId != null  and query.userId != \"\"' >" +
            " AND user_id = #{query.userId} " +
            "</if>" +
            " </script>")
    public List<PersonalAccessTokenVO> findList(@Param("query") PersonalAccessTokenQuery query);

}